import os
import sys
import time


def get_path_dir(apk_path):
    path = os.path.dirname(apk_path)
    return path


def get_file_name(apk_path):
    name = os.path.basename(apk_path)
    return name


def do_commond(commond):
    os.system(commond)


def get_now():
    now = time.strftime("%y%m%d-%H%M", time.localtime(time.time()))
    return now


if len(sys.argv) > 1:
    proj_dir = sys.path[0]
    apk_path = sys.argv[1]
    apk_dir = get_path_dir(apk_path)
    name = get_file_name(apk_path)
    # sign_name = get_now() + "_sign.apk"
    sign_name = "ANC.apk"

    commond = "cd " + proj_dir
    commond += " && java -jar signapk.jar platform.x509.pem platform.pk8 " + \
        apk_path + " " + apk_dir + "/" + sign_name
    commond += " && open " + apk_dir
    devices = ""
    # if len(sys.argv) > 2:
    #     devices += " -s " + sys.argv[2]
    # commond += " && adb" + devices + " install -r " + apk_dir + "/" + sign_name
    print commond
    do_commond(commond)

else:
    print "not input apk path"

# print "sys.argv[0]:" + sys.argv[0]
# print "sys.argv[1]:" + sys.argv[1]
# os.system("adb shell")
# raw_input("Press the enter key to continue.")
